#include "Globals.hpp"

Globals*  Globals::m_instance = 0;

Globals::Globals()
{
	m_lightTex = -1;
	m_shadowMap = -1;

	m_lightModelViewMatrix  = new GLdouble[16];
	m_lightProjectionMatrix = new GLdouble[16];

	m_cameraModelViewMatrix  = new GLdouble[16];
	m_cameraProjectionMatrix = new GLdouble[16];

	for( int i = 0; i < 16; ++i )
		m_lightModelViewMatrix[i] = m_lightProjectionMatrix[i] = m_cameraModelViewMatrix[i] = m_cameraProjectionMatrix[i] = 0.0;
}

Globals* Globals::GetInstance()
{
	if( !m_instance )
	{
		m_instance = new Globals;
	}

	return m_instance;
}

void Globals::SetSpecialTexture(GLuint lTex, SpecialTexture type )
{
}

GLuint* Globals::GetSpecialTexture( SpecialTexture type )
{
	switch( type )
	{
	case LIGHT_POSITIONS:
		return &m_lightTex;

	case SHADOW_MAP:
		return &m_shadowMap;

	default:
		return 0;
	}
}

GLdouble* Globals::GetLightMatrix(LightMatrix matrix)
{
	switch( matrix )
	{
	case MODELVIEW_MATRIX:
		return m_lightModelViewMatrix;

	case PROJECTION_MATRIX:
		return m_lightProjectionMatrix;

	default:
		return 0;
	}
}

GLdouble* Globals::GetCameraMatrix(LightMatrix matrix)
{
	switch( matrix )
	{
	case MODELVIEW_MATRIX:
		return m_cameraModelViewMatrix;

	case PROJECTION_MATRIX:
		return m_cameraProjectionMatrix;

	default:
		return 0;
	}
}

void Globals::SetCameraMatrix(LightMatrix matrix, MMatrix4 &mData)
{
	switch( matrix )
	{
	case MODELVIEW_MATRIX:
		m_cameraModelViewMatrix[0] = mData.m_matrix[0];
		m_cameraModelViewMatrix[1] = mData.m_matrix[1];
		m_cameraModelViewMatrix[2] = mData.m_matrix[2];
		m_cameraModelViewMatrix[3] = mData.m_matrix[3];
		m_cameraModelViewMatrix[4] = mData.m_matrix[4];
		m_cameraModelViewMatrix[5] = mData.m_matrix[5];
		m_cameraModelViewMatrix[6] = mData.m_matrix[6];
		m_cameraModelViewMatrix[7] = mData.m_matrix[7];
		m_cameraModelViewMatrix[8] = mData.m_matrix[8];
		m_cameraModelViewMatrix[9] = mData.m_matrix[9];
		m_cameraModelViewMatrix[10] = mData.m_matrix[10];
		m_cameraModelViewMatrix[11] = mData.m_matrix[11];
		m_cameraModelViewMatrix[12] = mData.m_matrix[12];
		m_cameraModelViewMatrix[13] = mData.m_matrix[13];
		m_cameraModelViewMatrix[14] = mData.m_matrix[14];
		m_cameraModelViewMatrix[15] = mData.m_matrix[15];
		break;

	case PROJECTION_MATRIX:
		m_cameraProjectionMatrix[0] = mData.m_matrix[0];
		m_cameraProjectionMatrix[1] = mData.m_matrix[1];
		m_cameraProjectionMatrix[2] = mData.m_matrix[2];
		m_cameraProjectionMatrix[3] = mData.m_matrix[3];
		m_cameraProjectionMatrix[4] = mData.m_matrix[4];
		m_cameraProjectionMatrix[5] = mData.m_matrix[5];
		m_cameraProjectionMatrix[6] = mData.m_matrix[6];
		m_cameraProjectionMatrix[7] = mData.m_matrix[7];
		m_cameraProjectionMatrix[8] = mData.m_matrix[8];
		m_cameraProjectionMatrix[9] = mData.m_matrix[9];
		m_cameraProjectionMatrix[10] = mData.m_matrix[10];
		m_cameraProjectionMatrix[11] = mData.m_matrix[11];
		m_cameraProjectionMatrix[12] = mData.m_matrix[12];
		m_cameraProjectionMatrix[13] = mData.m_matrix[13];
		m_cameraProjectionMatrix[14] = mData.m_matrix[14];
		m_cameraProjectionMatrix[15] = mData.m_matrix[15];
		break;
	}
}

void Globals::SetLightMatrix(LightMatrix matrix, MMatrix4 &mData)
{
	switch( matrix )
	{
	case MODELVIEW_MATRIX:
		m_lightModelViewMatrix[0] = mData.m_matrix[0];
		m_lightModelViewMatrix[1] = mData.m_matrix[1];
		m_lightModelViewMatrix[2] = mData.m_matrix[2];
		m_lightModelViewMatrix[3] = mData.m_matrix[3];
		m_lightModelViewMatrix[4] = mData.m_matrix[4];
		m_lightModelViewMatrix[5] = mData.m_matrix[5];
		m_lightModelViewMatrix[6] = mData.m_matrix[6];
		m_lightModelViewMatrix[7] = mData.m_matrix[7];
		m_lightModelViewMatrix[8] = mData.m_matrix[8];
		m_lightModelViewMatrix[9] = mData.m_matrix[9];
		m_lightModelViewMatrix[10] = mData.m_matrix[10];
		m_lightModelViewMatrix[11] = mData.m_matrix[11];
		m_lightModelViewMatrix[12] = mData.m_matrix[12];
		m_lightModelViewMatrix[13] = mData.m_matrix[13];
		m_lightModelViewMatrix[14] = mData.m_matrix[14];
		m_lightModelViewMatrix[15] = mData.m_matrix[15];
		break;

	case PROJECTION_MATRIX:
		m_lightProjectionMatrix[0] = mData.m_matrix[0];
		m_lightProjectionMatrix[1] = mData.m_matrix[1];
		m_lightProjectionMatrix[2] = mData.m_matrix[2];
		m_lightProjectionMatrix[3] = mData.m_matrix[3];
		m_lightProjectionMatrix[4] = mData.m_matrix[4];
		m_lightProjectionMatrix[5] = mData.m_matrix[5];
		m_lightProjectionMatrix[6] = mData.m_matrix[6];
		m_lightProjectionMatrix[7] = mData.m_matrix[7];
		m_lightProjectionMatrix[8] = mData.m_matrix[8];
		m_lightProjectionMatrix[9] = mData.m_matrix[9];
		m_lightProjectionMatrix[10] = mData.m_matrix[10];
		m_lightProjectionMatrix[11] = mData.m_matrix[11];
		m_lightProjectionMatrix[12] = mData.m_matrix[12];
		m_lightProjectionMatrix[13] = mData.m_matrix[13];
		m_lightProjectionMatrix[14] = mData.m_matrix[14];
		m_lightProjectionMatrix[15] = mData.m_matrix[15];
		break;
	}
}
mvMatricesVec Globals::GetLookAtMaticesVector()
{
	return m_lookAtMatrices;
}

void Globals::AddLookAtMatrix( LookAtMatrix* newMatrix )
{
	m_lookAtMatrices.push_back( newMatrix );
}